package dk.rafaelcouto.PhoneTone_Extractor;

import android.os.*;
import java.io.*;

public class AudioRecorder
{
    final String path;
    
    public AudioRecorder(final String s) {
        this.path = this.sanitizePath(s);
    }
    
    private String sanitizePath(String s) {
        if (!s.startsWith("/")) {
            s = "/" + s;
        }
        if (!s.contains(".")) {
            s = String.valueOf(s) + ".3gp";
        }
        return String.valueOf(Environment.getExternalStorageDirectory().getAbsolutePath()) + s;
    }
    
    public void start() throws IOException {
        final String externalStorageState = Environment.getExternalStorageState();
        if (!externalStorageState.equals("mounted")) {
            throw new IOException("SD Card is not mounted.  It is " + externalStorageState + ".");
        }
        final File parentFile = new File(this.path).getParentFile();
        if (!parentFile.exists() && !parentFile.mkdirs()) {
            throw new IOException("Path to file could not be created.");
        }
    }
    
    public void stop() throws IOException {
    }
}
